package apache;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

import mvc.action.Action;

public class ClientService implements Runnable {
	private Socket client;

	public ClientService() {
		
	}

	public ClientService(Socket client) {
		this.client = client;
	}

	@Override
	public void run() {
		try {
			/* 接收请求信息 */
			InputStream in =client.getInputStream();// 输入流
			OutputStream  out = client.getOutputStream();// 输出流
			inHandle(in, out);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 对请求内容进行处理
	 * 
	 * @param request
	 */
	public void inHandle(InputStream in, OutputStream out) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			new Action().doGet(reader, out);
		} catch (Exception e) {
			System.out.println("处理请求内容出问题了");
			e.printStackTrace();
		} finally {
			try {
				if (out != null)  
                    out.close(); 
				client.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
